package com.crazyant;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ImageButton;
import android.widget.RadioButton;

public class Options extends Activity {

	private int id = 0;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.options);
        final RadioButton boton0 = (RadioButton)findViewById(R.id.color0);
        final RadioButton boton1 = (RadioButton)findViewById(R.id.color1);
        final RadioButton boton2 = (RadioButton)findViewById(R.id.color2);
        final RadioButton boton3 = (RadioButton)findViewById(R.id.color3);
        
        ImageButton guardar = (ImageButton) findViewById(R.id.save);
		guardar.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if(boton0.isChecked()) {
					if(GV.BBDD.r == 1) {
						Ant a = GV.BBDD.dbhandler.getAnt(GV.BBDD.color);
						id = GV.BBDD.dbhandler.BuscaAnt(0, a.getCuerpo(), a.getCasco(), a.getBotas(), a.getUser());
						GV.BBDD.dbhandler.updateContact(a.getUser(), id);
						GV.BBDD.color = id;
					}
					else GV.BBDD.color = 0;
				}
				else if(boton1.isChecked()) {
					if(GV.BBDD.r == 1) {
						Ant a = GV.BBDD.dbhandler.getAnt(GV.BBDD.color);
						id = GV.BBDD.dbhandler.BuscaAnt(1, a.getCuerpo(), a.getCasco(), a.getBotas(), a.getUser());
						GV.BBDD.dbhandler.updateContact(a.getUser(), id);
						GV.BBDD.color = id;
					}
					else GV.BBDD.color = 1;
				}
				else if(boton2.isChecked()) {
					if(GV.BBDD.r == 1) {
						Ant a = GV.BBDD.dbhandler.getAnt(GV.BBDD.color);
						id = GV.BBDD.dbhandler.BuscaAnt(2, a.getCuerpo(), a.getCasco(), a.getBotas(), a.getUser());
						GV.BBDD.dbhandler.updateContact(a.getUser(), id);
						GV.BBDD.color = id;
					}
					else GV.BBDD.color = 2;
				}
				else if(boton3.isChecked()) {
					if(GV.BBDD.r == 1) {
						Ant a = GV.BBDD.dbhandler.getAnt(GV.BBDD.color);
						id = GV.BBDD.dbhandler.BuscaAnt(3, a.getCuerpo(), a.getCasco(), a.getBotas(), a.getUser());
						Log.d("CUERPO ROJO ID", "IDENTIFICADOR "+ id);
						Log.d("CONTADOR ROWS", ""+GV.BBDD.dbhandler.getAntCount());
						GV.BBDD.dbhandler.updateContact(a.getUser(), id);
						GV.BBDD.color = id;
					}
					else GV.BBDD.color = 3;
				}
			}
		});
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_options, menu);
        return true;
    }
}
